home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------- calls.c ----------------------------------*/
- /* Copyright 1989 Brown University -- Jeffrey Vogel */
- /*----------------------------------------------------------------------------*/
-
-
- /*--------------------------------- Include ---------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- #include "qd_local.h"
-
- /*--------------------------------- Statics ----------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- static XSetWindowAttributes QDwindowAttributes;
-
-
- /*--------------------------------- InitDraw ---------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- void
- InitDraw(width, height)
- int width, height;
- {
- XSizeHints size_hints;
- XEvent report;
-
- /*** error checks ***/
- if (QDrunning) {
- QDerror("ERROR InitDraw: QuickDraw already initialized.");
- return;
- }
- if ((width < 0) || (height < 0)) {
- QDerror("ERROR InitDraw: Bad size parameters.");
- return;
- }
-
- /*** initializing ***/
- if (!QDdisplay) {
- QDopen(NULL, NULL);
- if (!QDdisplay) {
- QDerror("ERROR InitDraw: Unable to open display.");
- return;
- }
- QDautoDisplay = TRUE;
- }
- else
- QDautoDisplay = FALSE;
-
-
- if ((width >= DisplayWidth(QDdisplay, QDscreen))) {
- QDerror("ERROR InitDraw: Width too big.");
- return;
- }
- if ((height >= DisplayHeight(QDdisplay, QDscreen))) {
- QDerror("ERROR InitDraw: Height too big.");
- return;
- }
-
-
-
-
-
-
-
-
-
- /*** initialize variables ***/
- QDrunning = TRUE;
- QDwidth = width;
- QDheight = height;
- QDx = QDy = 0;
- srandom(1);
-
- /*** set initial attributes ***/
- QDgcValues.line_width = LINE_WIDTH__DEFAULT;
- QDgcValues.fill_style = FillSolid;;
- QDgcValues.line_style = LINE_STYLE__DEFAULT;
- QDgcValues.function = FUNCTION__DEFAULT;;
- QDgcValues.font = QDfonts[FONT__DEFAULT];
- QDgcValues.foreground = BlackPixel(QDdisplay, QDscreen);
- QDgcValues.background = WhitePixel(QDdisplay, QDscreen);
- XChangeGC(QDdisplay, QDgc,
- GCForeground|GCBackground|GCLineWidth|GCFont|
- GCFunction|GCLineStyle|GCFillStyle,
- &QDgcValues);
-
- /*** Build window ***/
- QDwindow = XCreateSimpleWindow(QDdisplay,
- QDroot,
- 0, 0, (width == 0) ? 100 : width,
- (height == 0) ? 100 : height,
- 2,
- BlackPixel(QDdisplay, QDscreen),
- WhitePixel(QDdisplay, QDscreen));
- XSelectInput(QDdisplay, QDwindow, StructureNotifyMask);
-
- /*** size hints ***/
- size_hints.flags = PPosition|PSize;
- size_hints.width = width;
- size_hints.height = height;
- XSetStandardProperties(QDdisplay, QDwindow, "QuickDraw",
- "QuickDraw", None, NULL, 0, &size_hints);
-
- QDwindowAttributes.backing_store = Always;
- QDwindowAttributes.colormap = QDcolormap;
- XChangeWindowAttributes(QDdisplay, QDwindow,
- CWColormap|CWBackingStore,
- &QDwindowAttributes);
-
- /*** map window ***/
- XMapRaised(QDdisplay, QDwindow);
- do {
- XNextEvent(QDdisplay, &report);
- } while ((report.type != MapNotify) || (report.xany.window != QDwindow));
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /*-------------------------------- InitDraw4 ---------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- void
- InitDraw4(width, height, x, y)
- int width, height, x, y;
- {
- XSizeHints size_hints;
- XEvent report;
-
- /*** error checks ***/
- if (QDrunning) {
- QDerror("ERROR InitDraw: QuickDraw already initialized.");
- return;
- }
- if ((width < 0) || (height < 0)) {
- QDerror("ERROR InitDraw: Bad size parameters.");
- return;
- }
-
- /*** initializing ***/
- if (!QDdisplay) {
- QDopen(NULL, NULL);
- if (!QDdisplay) {
- QDerror("ERROR InitDraw: Unable to open display.");
- return;
- }
- QDautoDisplay = TRUE;
- }
- else
- QDautoDisplay = FALSE;
-
-
- if ((width >= DisplayWidth(QDdisplay, QDscreen))) {
- QDerror("ERROR InitDraw: Width too big.");
- return;
- }
- if ((height >= DisplayHeight(QDdisplay, QDscreen))) {
- QDerror("ERROR InitDraw: Height too big.");
- return;
- }
-
-
- /*** initialize variables ***/
- QDrunning = TRUE;
- QDwidth = width;
- QDheight = height;
- QDx = QDy = 0;
- srandom(1);
-
- /*** set initial attributes ***/
- QDgcValues.line_width = LINE_WIDTH__DEFAULT;
- QDgcValues.fill_style = FillSolid;;
- QDgcValues.line_style = LINE_STYLE__DEFAULT;
- QDgcValues.function = FUNCTION__DEFAULT;;
- QDgcValues.font = QDfonts[FONT__DEFAULT];
- QDgcValues.foreground = BlackPixel(QDdisplay, QDscreen);
- QDgcValues.background = WhitePixel(QDdisplay, QDscreen);
- XChangeGC(QDdisplay, QDgc,
- GCForeground|GCBackground|GCLineWidth|GCFont|
- GCFunction|GCLineStyle|GCFillStyle,
- &QDgcValues);
-
-
-
-
- /*** Build window ***/
- QDwindow = XCreateSimpleWindow(QDdisplay,
- QDroot,
- 0, 0, (width == 0) ? 100 : width,
- (height == 0) ? 100 : height,
- 2,
- BlackPixel(QDdisplay, QDscreen),
- WhitePixel(QDdisplay, QDscreen));
- XSelectInput(QDdisplay, QDwindow, StructureNotifyMask);
-
- /*** size hints ***/
- size_hints.flags = USPosition|USSize;
- size_hints.width = width;
- size_hints.height = height;
- size_hints.x = x;
- size_hints.y = y;
- XSetStandardProperties(QDdisplay, QDwindow, "QuickDraw",
- "QuickDraw", None, NULL, 0, &size_hints);
-
- QDwindowAttributes.backing_store = Always;
- QDwindowAttributes.colormap = QDcolormap;
- XChangeWindowAttributes(QDdisplay, QDwindow,
- CWColormap|CWBackingStore,
- &QDwindowAttributes);
-
- /*** map window ***/
- XMapRaised(QDdisplay, QDwindow);
- do {
- XNextEvent(QDdisplay, &report);
- } while ((report.type != MapNotify) || (report.xany.window != QDwindow));
- }
-
-
-
- /*--------------------------------- ClearAll ---------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- void
- ClearAll()
- {
- /*** error check ***/
- if (!QDrunning) {
- QDerror("ERROR ClearAll: QuickDraw not initialized.");
- return;
- }
-
- XClearWindow(QDdisplay, QDwindow);
- XFlush(QDdisplay);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /*--------------------------------- QuitDraw ---------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- void
- QuitDraw()
- {
- register int i;
-
- if (!QDrunning) {
- QDerror("ERROR QuitDraw: Never initialized.");
- return;
- }
-
- XDestroyWindow(QDdisplay, QDwindow);
- QDrunning = FALSE;
- QDwindow = NULL;
- XFlush(QDdisplay);
-
- if (QDautoDisplay)
- QDclose();
- }
-
-
-
- /*------------------------------ GetDrawingRect ------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- void
- GetDrawingRect(r)
- Rect *r;
- {
- XWindowAttributes atts;
-
- /*** error check ***/
- if (!QDrunning) {
- QDerror("ERROR GetDrawingRect: QuickDraw not initialized.");
- return;
- }
-
- XGetWindowAttributes(QDdisplay, QDwindow, &atts);
-
- r->left = 0;
- r->top = 0;
- r->right = atts.width;
- r->bottom = atts.height;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /*--------------------------------- DrawGrid ---------------------------------*/
- /*----------------------------------------------------------------------------*/
-
- void
- DrawGrid(spacing)
- int spacing;
- {
- XWindowAttributes atts;
- int w, h;
- register int i;
-
- /*** error check ***/
- if (!QDrunning) {
- QDerror("ERROR DrawGrid: QuickDraw not initialized.");
- return;
- }
-
- XGetWindowAttributes(QDdisplay, QDwindow, &atts);
- w = atts.width;
- h = atts.height;
-
- /*** vertical lines ***/
- for (i = 0; i < (w / spacing); i++)
- XDrawLine(QDdisplay, QDwindow, QDgridgc,
- i*spacing, h, i*spacing, 0);
-
- /*** horizontal lines ***/
- for (i = 0; i < (h / spacing); i++)
- XDrawLine(QDdisplay, QDwindow, QDgridgc,
- 0, i*spacing, w, i*spacing);
-
- XFlush(QDdisplay);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-